import commit from './hooks/commit';
import gui from './hooks/gui';
import publish from './hooks/publish';
import expansion from './hooks/expansion';
import pkg from '../package.json';
import ExtractDictByPDF from './hooks/ExtractDictByPDF';
import logger from './utils/logger';

const payload = process.argv;

const help = `
  🏄  ${pkg.name} v.${pkg.version}

  Usage:
    -h              查看帮助
    -v              版本信息
    -i              作者信息
    -gui            调起命令行工具，可查看并选择执行以下功能

    ******************** 以下为功能参数 ********************

    -push           <path> 规范化推送代码     path: 可选，版本日志路径
    -publish        <path> 发布npm包          path: 可选，需要发布的子文件夹路径
    -expansion      <path> 展开代码仓库       path: 必选，配置文件路径
    -extractDict    <path> pdf提取单词本      path: 必选，pdf地址
    -create         依据模板创建项目（待开放）
`;

const info = `
  🐼   作者:         ${pkg.author.name}
  📧   联系方式:     ${pkg.author.email}
  🏠   仓库:         ${pkg.repository.url}
  🏘️    npm:          ${pkg.publishConfig.registry}/${pkg.name}
  🏄   issues:       ${pkg.bugs.url}
`

const fixArgLen = 2;
if (payload.length <= fixArgLen) logger.log(help)
else {
  const argv = payload.slice(fixArgLen);

  switch (argv[0]) {
    case '-h':
      logger.log(help);
      break;
    case '-v':
      logger.log(`\n\n${pkg.name} v${pkg.version}\nlastModify: ${pkg.lastModify}\n\n`);
      break;
    case '-i':
      logger.log(info);
      break;
    case '-gui':
      gui();
      break;

    case '-push':
      commit(argv[1]);
      break;
    case '-publish':
      publish(argv[1]);
      break;
    case '-expansion':
      if (!argv[1]) logger.error('请指定配置文件路径')
      else expansion(argv[1])
      break;
    case '-extractDict':
      if (!argv[1]) logger.error('请指定配置文件路径')
      else ExtractDictByPDF(argv[1])
      break;
    default:
      break;
  }
}

